//
//  postCollectionViewCell.m
//  timemovie
//
//  Created by Yiqiao on 15/7/24.
//  Copyright (c) 2015年 Yiqiao. All rights reserved.
//

#import "postCollectionViewCell.h"
#import "UIViewExt.h"
#import "UIImageView+WebCache.h"
#import "postDetail.h"

@implementation postCollectionViewCell

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self _createSubview];
    }
    return self;
}

- (void)_createSubview{    
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *views = [bundle loadNibNamed:@"posterDetail" owner:self options:nil];
    _posterDetail = [views lastObject];
    _posterDetail.hidden = YES;
    _posterDetail.frame = CGRectMake((self.width-self.width*0.9)/2, (self.height-self.height*0.9)/2, self.width*0.9, self.height*0.9);
    [self addSubview:_posterDetail];
    
    _imageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.width-self.width*0.9)/2, (self.height-self.height*0.9)/2, self.width*0.9, self.height*0.9)];
    [self.contentView addSubview:_imageView];
    
}

- (void)setModel:(MObj *)model{
    _model = model;
    _posterDetail.model = model;
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    NSString *str = [_model.images objectForKey:@"large"];
    [_imageView sd_setImageWithURL:[NSURL URLWithString:str]];
    if (_isBack) {
        _posterDetail.hidden = NO;
        _imageView.hidden = YES;
    }
    else{
        _posterDetail.hidden = YES;
        _imageView.hidden = NO;
    }
    
}

- (void)flipCell{
    [self flipViewAni:self isLeft:_imageView.hidden];
    _posterDetail.hidden =!_posterDetail.hidden;
    _imageView.hidden  =!_imageView.hidden;
}

- (void)flipViewAni: (UIView*)view isLeft:(BOOL)ISLeft{
    UIViewAnimationOptions option = ISLeft?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;
    [UIView transitionWithView:view duration:0.5 options:option animations:nil completion:nil];
}


    


@end
